package org.enwey.icarenew.Adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;

import org.enwey.icarenew.Component.NewItem;
import org.enwey.icarenew.Model.New;

import java.util.List;

/**
 * Created by enwey on 2014/11/20.
 */
public class NewAdapter extends BaseAdapter {
    private List<New> mNewList;
    private Context context;

    public NewAdapter(Context context) {
        this.context = context;
    }
    public void setNewList(List<New> list) {
        this.mNewList = list;
    }
    @Override
    public int getCount() {
        return (mNewList != null ? mNewList.size() : 0);
    }

    @Override
    public Object getItem(int position) {
        return (mNewList != null ? mNewList.get(position) : null);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        NewItem newItem = null;
        if (convertView == null) {
            newItem = new NewItem(context);
        }else {
            newItem = (NewItem) convertView;
        }

        newItem.setNewData(mNewList.get(position));

        return newItem;
    }
}
